<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>Demo</title>
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="stylesheet" type="text/css" href="static/css/resetcss.css">
  <link rel="stylesheet" type="text/css" href="static/css/play.css">
  <script type="text/javascript" src="static/js/jquery.min.js"></script>
  <style>
    .driveBtn {
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      -khtml-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
    }
  </style>
</head>
<body style="padding: 0;margin: 0;overflow: hidden;">
  <div style="position: absolute;z-index: 99;width: 100%;height: 100%;">
    <div class="screenwarp">
      <div class="controlwarp">
        <div class="controlbtnup btn driveBtn"></div>
        <div class="controlbtnright btn driveBtn"></div>
        <div class="controlbtndown btn driveBtn"></div>
        <div class="controlbtnleft btn driveBtn"></div>
      </div>
      <div class="functionwarp">
        <div class="functiontop">
          <div class="functiontop-left">
            <div class="autocross-off"></div><span>避障</span><p class="autocross-text text">开启</p>
          </div>
          <div class="functiontop-left">
            <div class="cruise-off"></div><span>寻迹</span><p class="cruise-text text">开启</p>
          </div>
          <div class="functiontop-right">
            <div class="light-off"></div><span>照明</span><p class="light-text text">开启</p>
          </div>
        </div>
        <div class="functionmiddle">
          <div class="camera-up btnsmall"></div>
          <div class="camera-right btnsmall"></div>
          <div class="camera-down btnsmall"></div>
          <div class="camera-left btnsmall"></div>
          <div class="camera-middle"><div class="camera-on"></div></div>
          <p class="voice-texts">摄像头云台</p>
        </div>
        <div class="functionbottom">
          <div class="voice-left btnsmall"></div>
          <div class="voice-right btnsmall"></div>
          <div class="voice-middle"><div class="voice-on"></div></div>
          <p class="voice-textv">超声波云台</p>
        </div>
      </div>
    </div>
  </div>
  <div>
    <img id="streamimage" class="" src="http://192.168.0.214:8080/?action=stream" width="100%" height="100%">
  </div>
  <script>
    $(document).ready(function(){
        resize();
        window.addEventListener("resize", resize)
        // 点击添加波纹
        var wave = '<div class="wave-circle"></div>';
        $('.btn').click(function (){
            $(this).siblings('.btn').empty();
            $(this).empty().append(wave);
        });
        var wavesmall = '<div class="wave-circlesmall"></div>';
        $('.btnsmall').click(function (){
            $(this).siblings('.btnsmall').empty();
            $(this).empty().append(wavesmall);
        });
        // 驾驶
        $('.controlbtnup').on('touchstart', function(){
            action('drive/forward');
        });
        $('.controlbtndown').on('touchstart', function(){
            action('drive/backOff');
        });
        $('.controlbtnleft').on('touchstart', function(){
            action('drive/leftTurn');
        });
        $('.controlbtnright').on('touchstart', function(){
            action('drive/rightTurn');
        });
        $('.driveBtn').on('touchend', function(){
            action('drive/stop');
        });
        // 超声波云台
        $('.voice-left').click(function(){
            action('servoUltrasonic/leftTurn');
        });
        $('.voice-right').click(function(){
            action('servoUltrasonic/rightTurn');
        });
        // 摄像头云台
        $('.camera-up').click(function(){
            action('servoCamera/upTurn');
        });
        $('.camera-down').click(function(){
            action('servoCamera/downTurn');
        });
        $('.camera-left').click(function(){
            action('servoCamera/leftTurn');
        });
        $('.camera-right').click(function(){
            action('servoCamera/rightTurn');
        });
        // 灯
        $(".light-off").toggle(function(){
            $(".light-off").addClass("light-on");
            $(".light-text").html("关闭");
            action('light/turnOn');
        },function(){
            $(".light-off").removeClass("light-on");
            $(".light-text").html("开启");
            action('light/turnOff');
        });
        // 寻迹
        $(".cruise-off").toggle(function(){
            $(".cruise-off").addClass("cruise-on");
            $(".cruise-text").html("开启");
            action('cruise/turnOn');
        },function(){
            $(".cruise-off").removeClass("cruise-on");
            $(".cruise-text").html("关闭");
            action('cruise/turnOff');
        });
        // 避障
        $(".autocross-off").toggle(function(){
            $(".autocross-off").addClass("autocross-on");
            $(".autocross-text").html("开启");
            action('autocross/turnOn');
        },function(){
            $(".autocross-off").removeClass("autocross-on");
            $(".autocross-text").html("关闭");
            action('autocross/turnOff');
        });
    });

    function action(url){
        $.ajax({
            type: 'get',
            url: url,
            //data: {type:'turnOn'},
            success: function (data) {
                console.log(data.success);
            }
        })
    }

    function resize() {
        var body = document.getElementsByTagName('body')[0];
        var html = document.getElementsByTagName('html')[0];
        var width = html.clientWidth;
        var height =  html.clientHeight;
        var max = width > height ? width : height;
        var min = width > height ? height : width;
        body.style.width = max + "px";
        body.style.height = min + "px";
    }
  </script>
</body>
</html>